package com.jam.cloud.order.service;

import com.jam.cloud.order.mapper.OrderMapper;
import com.jam.cloud.order.pojo.Order;
import com.netflix.appinfo.InstanceInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Service
public class OrderService {

    @Autowired
    OrderMapper orderMapper;

    @Autowired
    RestTemplate restTemplate;



    @Autowired
    DiscoveryClient discoveryClient;

    public Order queryById(Long id){
//        List<ServiceInstance> userserver = discoveryClient.getInstances("userserver");
        Order order = orderMapper.queryById(id);
        String url = "http://userserver/user/" + order.getUserId();
//        String url = "http://localhost:8081/user/" + order.getUserId();
        Object user =   restTemplate.getForObject(url,Object.class);
        order.setUser(user);
        return order;
    }

}
